/**
 * 
 */
package sailing.filters;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import sailing.listener.UI;

import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

/**
 * @author kevin
 * 
 */
public abstract class Filter {

	private String name;

	protected static final String colSpec = "1dlu,r:70dlu,3dlu,f:150dlu:g,3dlu,r:18dlu,3dlu";
	protected static final String rowSpec = "0dlu,18dlu,0dlu";

	protected static FormLayout layout = new FormLayout(colSpec, rowSpec);
	private JButton removeBtn;
	private Insets margin = new Insets(0, 1, 0, 1);
	private Dimension removeBtnSize = new Dimension(20, 20);

	public Filter(String name) {
		this.name = name;
	}

	public String getName() {
		return this.name;
	}

	public Component getFilterCallPanel() {
		JPanel cellPanel = new JPanel();
		// JPanel cellPanel = new FormDebugPanel(true, true);
		// cellPanel.setBorder(BorderFactory.createTitledBorder(""));
		cellPanel.setLayout(this.layout);

		CellConstraints cc = new CellConstraints();
		JLabel name = new JLabel(this.name + ":");
		name.setFont(UI.font12);
		cellPanel.add(name, cc.xy(2, 2));

		Component cellP = this.getInternalCellPanel();
		cellPanel.add(cellP, cc.xy(4, 2));

		removeBtn = new JButton("X") {

			@Override
			public Dimension getPreferredSize() {
				return removeBtnSize;
			}

			@Override
			public Dimension getMaximumSize() {
				return removeBtnSize;
			}

			@Override
			public Dimension getMinimumSize() {
				return removeBtnSize;
			}
		};
		removeBtn.setMargin(margin);
		removeBtn.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

			}
		});
		cellPanel.add(removeBtn, cc.xy(6, 2));

		return cellPanel;
	}

	protected abstract Component getInternalCellPanel();

	public JButton getRemoveBtn() {
		return this.removeBtn;
	}

}
